<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">

	<title>KSYMediaPlayback Protocol Reference</title>

	<link rel="stylesheet" href="../css/style.css">
	<meta name="viewport" content="initial-scale=1, maximum-scale=1.4">
	<meta name="generator" content="appledoc 2.2.1 (build 1334)">
</head>
<body class="appledoc">
	<header>
		<div class="container" class="hide-in-xcode">
			
			<h1 id="library-title">
				<a href="../index.html">KSYPlayer </a>
			</h1>

			<p id="developer-home">
				<a href="../index.html">VideoCloud</a>
			</p>
			
		</div>
	</header>

	<aside>
		<div class="container">
			<nav>
				<ul id="header-buttons" role="toolbar">
					<li><a href="../index.html">Index</a></li>
<li><a href="../hierarchy.html">Hierarchy</a></li>

					<li id="on-this-page" role="navigation">
						<label>
							On This Page

							<div class="chevron">
								<div class="chevy chevron-left"></div>
								<div class="chevy chevron-right"></div>
							</div>

							<select id="jump-to">
	<option value="top">Jump To&#133;</option>
	
	<option value="overview">Overview</option>
	

	
	
	<option value="tasks">Tasks</option>
	
	

	
	
	<optgroup label="Properties">
		
		<option value="//api/name/currentPlaybackTime">currentPlaybackTime</option>
		
		<option value="//api/name/isPreparedToPlay">isPreparedToPlay</option>
		
	</optgroup>
	

	

	
	<optgroup label="Instance Methods">
		
		<option value="//api/name/pause">- pause</option>
		
		<option value="//api/name/play">- play</option>
		
		<option value="//api/name/prepareToPlay">- prepareToPlay</option>
		
		<option value="//api/name/stop">- stop</option>
		
	</optgroup>
	
	
</select>
						</label>
					</li>
				</ul>
			</nav>
		</div>
	</aside>

	<article>
		<div id="overview_contents" class="container">
			<div id="content">
				<main role="main">
					<h1 class="title">KSYMediaPlayback Protocol Reference</h1>

					
					<div class="section section-specification"><table cellspacing="0"><tbody>
						<tr>
	<th>Declared in</th>
	<td>KSYMediaPlayback.h</td>
</tr>
						</tbody></table></div>
					

                    
					
					<div class="section section-overview">
						<a title="Overview" name="overview"></a>
						<h2 class="subtitle subtitle-overview">Overview</h2>
						<p>KSYMediaPlayback为播放内核<a href="../Classes/KSYMoviePlayerController.html">KSYMoviePlayerController</a>提供播放控制功能。</p>

<h2>联系我们</h2>

<p>当本文档无法帮助您解决在开发中遇到的具体问题，请通过以下方式联系我们，金山云工程师会在第一时间回复您。</p>

<p><strong>E-mail</strong>:  zengfanping@kingsoft.com</p>
					</div>
					
					

					
					
					<div class="section section-tasks">
						<a title="Tasks" name="tasks"></a>
						

						
						

						<div class="task-list">
							<div class="section-method">
	<a name="//api/name/prepareToPlay" title="prepareToPlay"></a>
	<h3 class="method-title"><code><a href="#//api/name/prepareToPlay">&ndash;&nbsp;prepareToPlay</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>准备视频播放</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>- (void)prepareToPlay</code></div>

		    
			

			

			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>prepareToPlay处理逻辑</p>

<ul>
<li>如果isPreparedToPlay为FALSE，直接调用<a href="#//api/name/play">play</a>，则在play内部自动调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>接口。</li>
<li>prepareToPlay调用后，由MPMediaPlaybackIsPreparedToPlayDidChangeNotification通知完成准备工作。查询<a href="#//api/name/isPreparedToPlay">isPreparedToPlay</a>可以获得具体属性值。</li>
</ul>
<p>通知类型</p>

<ul>
<li>MPMediaPlaybackIsPreparedToPlayDidChangeNotification， 播放器完成对视频文件的初始化时发送通知</li>
</ul>

			</div>
			

			

			
			<div class="method-subsection see-also-section">
				<h4 class="method-subtitle">See Also</h4>
				<ul>
					
					<li><code><p><a href="#//api/name/isPreparedToPlay">@property isPreparedToPlay</a></p></code></li>
					
				</ul>
			</div>
			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div><div class="section-method">
	<a name="//api/name/isPreparedToPlay" title="isPreparedToPlay"></a>
	<h3 class="method-title"><code><a href="#//api/name/isPreparedToPlay">&nbsp;&nbsp;isPreparedToPlay</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>查询视频准备是否完成</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>@property (nonatomic, readonly) BOOL isPreparedToPlay</code></div>

		    
			

			

			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>isPreparedToPlay处理逻辑</p>

<ul>
<li>如果isPreparedToPlay为TRUE，则可以调用<a href="#//api/name/play">play</a>接口开始播放;</li>
<li>如果isPreparedToPlay为FALSE，则需要调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>接口开始准备工作；</li>
<li>如果isPreparedToPlay为FALSE，直接调用<a href="#//api/name/play">play</a>，则在play内部自动调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>接口。</li>
</ul>

			</div>
			

			

			
			<div class="method-subsection see-also-section">
				<h4 class="method-subtitle">See Also</h4>
				<ul>
					
					<li><code><p><a href="#//api/name/prepareToPlay">- prepareToPlay</a></p></code></li>
					
				</ul>
			</div>
			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div><div class="section-method">
	<a name="//api/name/play" title="play"></a>
	<h3 class="method-title"><code><a href="#//api/name/play">&ndash;&nbsp;play</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>播放当前视频。</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>- (void)play</code></div>

		    
			

			

			
			<div class="method-subsection availability">
				<h4 class="method-subtitle parameter-title">Availability</h4>
				<p>Available in KSYMediaPlayback 1.0 and later.</p>
			</div>
			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>play的使用逻辑:</p>

<ul>
<li>如果调用play方法前已经调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>完成播放器对视频文件的初始化，且<a href="../Classes/KSYMoviePlayerController.html#//api/name/shouldAutoplay">shouldAutoplay</a>属性为NO，则调用play方法将开始播放当前视频。此时播放器状态为CBPMoviePlaybackStatePlaying。</li>
<li>如果调用play方法前已经调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>完成播放器对视频文件的初始化，且<a href="../Classes/KSYMoviePlayerController.html#//api/name/shouldAutoplay">shouldAutoplay</a>属性为YES，则调用play方法将暂停播放当前视频，实现效果和pause一致。</li>
<li>如果调用play方法前未调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>完成播放器对视频文件的初始化，则播放器自动调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>进行视频文件的初始化工作。</li>
<li>如果调用play方法前已经调用pause暂停了正在播放的视频，则重新开始启动播放视频。</li>
</ul>

			</div>
			

			

			
			<div class="method-subsection see-also-section">
				<h4 class="method-subtitle">See Also</h4>
				<ul>
					
					<li><code><p><a href="#//api/name/prepareToPlay">- prepareToPlay</a></p></code></li>
					
				</ul>
			</div>
			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div><div class="section-method">
	<a name="//api/name/pause" title="pause"></a>
	<h3 class="method-title"><code><a href="#//api/name/pause">&ndash;&nbsp;pause</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>暂停播放当前视频。</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>- (void)pause</code></div>

		    
			

			

			
			<div class="method-subsection availability">
				<h4 class="method-subtitle parameter-title">Availability</h4>
				<p>Available in KSYMediaPlayback 1.0 and later.</p>
			</div>
			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>pause调用逻辑：</p>

<ul>
<li>如果当前视频播放已经暂停，调用该方法将不产生任何效果。</li>
<li>重新回到播放状态，需要调用<a href="#//api/name/play">play</a>方法。</li>
<li>如果调用pause方法后视频暂停播放，此时播放器状态处于CBPMoviePlaybackStatePaused。</li>
<li>播放器内部监听了UIApplicationWillEnterForegroundNotification通知，该通知发生时如果视频仍然在播放，将自动调用pause暂停当前视频播放。</li>
</ul>
<p>后台播放逻辑：</p>

<ul>
<li>需要APP有后台执行权限，在工程Info.plist中添加后台运行模式，设置为audio。具体是添加UIBackgroundModes项，值为audio。</li>
<li>当用户点击home按钮后，播放器进入后台继续读取数据并播放音频。</li>
<li>当APP回到前台后，音频继续播放。图像渲染内容保持和音频同步。</li>
<li>如果在开启后台运行模式后，需要切换后台暂停，需要监听相关事件并主动调用pause操作。</li>
</ul>

			</div>
			

			

			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div><div class="section-method">
	<a name="//api/name/stop" title="stop"></a>
	<h3 class="method-title"><code><a href="#//api/name/stop">&ndash;&nbsp;stop</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>结束当前视频的播放。</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>- (void)stop</code></div>

		    
			

			

			
			<div class="method-subsection availability">
				<h4 class="method-subtitle parameter-title">Availability</h4>
				<p>Available in KSYMediaPlayback 1.0 and later.</p>
			</div>
			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>stop调用逻辑：</p>

<ul>
<li>调用stop结束当前播放，如果需要重新播放该视频，需要调用<a href="#//api/name/prepareToPlay">prepareToPlay</a>方法。</li>
<li>调用stop方法后，播放器开始进入关闭当前播放的操作，操作完成将发送MPMoviePlayerPlaybackDidFinishNotification通知。</li>
</ul>
<p>通知：</p>

<ul>
<li>MPMoviePlayerPlaybackDidFinishNotification， 当播放完成将发送该通知。</li>
</ul>

			</div>
			

			

			
			<div class="method-subsection see-also-section">
				<h4 class="method-subtitle">See Also</h4>
				<ul>
					
					<li><code><p><a href="#//api/name/prepareToPlay">- prepareToPlay</a></p></code></li>
					
				</ul>
			</div>
			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div><div class="section-method">
	<a name="//api/name/currentPlaybackTime" title="currentPlaybackTime"></a>
	<h3 class="method-title"><code><a href="#//api/name/currentPlaybackTime">&nbsp;&nbsp;currentPlaybackTime</a></code>
<span class="task-item-suffix">required method</span></h3>

	<div class="method-info">
		<div class="pointy-thing"></div>

		<div class="method-info-container">
			
			
			<div class="method-subsection brief-description">
				<p>播放视频的当前时刻，单位为秒。</p>
			</div>
			
		    

			<div class="method-subsection method-declaration"><code>@property (nonatomic) NSTimeInterval currentPlaybackTime</code></div>

		    
			

			

			
			<div class="method-subsection availability">
				<h4 class="method-subtitle parameter-title">Availability</h4>
				<p>Available in KSYMediaPlayback 1.0 and later.</p>
			</div>
			

			
			<div class="method-subsection discussion-section">
				<h4 class="method-subtitle">Discussion</h4>
				<p>currentPlaybackTime属性更改时机：</p>

<ul>
<li>视频正常播放时，如果改变currentPlaybackTime的值，将导致播放行为跳转到新的currentPlaybackTime位置播放。</li>
<li>如果在视频未播放前设置currentPlaybackTime的值，将导致播放时刻从currentPlaybackTime位置播放。</li>
</ul>

			</div>
			

			

			

			
			<div class="method-subsection declared-in-section">
				<h4 class="method-subtitle">Declared In</h4>
				<p><code class="declared-in-ref">KSYMediaPlayback.h</code></p>
			</div>
			
			
		</div>
	</div>
</div>
						</div>
						
					</div>
					
					

                    
                    
          
				</main>

				<footer>
					<div class="footer-copyright">
						
						<p class="copyright">Copyright &copy; 2016 VideoCloud. All rights reserved. Updated: 2016-03-28</p>
						
						
						<p class="generator">Generated by <a href="http://appledoc.gentlebytes.com">appledoc 2.2.1 (build 1334)</a>.</p>
						
					</div>
				</footer>
			</div>
		</div>
	</article>

	<script src="../js/script.js"></script>
</body>
</html>